package cn.south.campus.admin.campus.model.vo;

import cn.south.campus.admin.campus.model.entity.Goods;
import cn.south.campus.common.file.service.ImgJsonDeSerializer;
import cn.south.campus.common.file.service.ImgJsonSerializer;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2024/11/14 8:58
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class GoodsVo extends BaseVO {
    /**
     * 分类id
     */
    private Long categoryId;

    /**
     * 分类名称
     */
    private String categoryName;

    /**
     * 商品名称
     */
    private String name;

    /**
     * 价格
     */
    private String price;

    /**
     * 图片地址
     */
    @JsonSerialize(using = ImgJsonSerializer.class)
    @JsonDeserialize(using = ImgJsonDeSerializer.class)
    private String url;

    /**
     * 发布人
     */
    private Long publisher;
    /**
     * 发布人名称
     */
    private String publisherName;

    /**
     * 库存
     */
    private Integer stock;

    /**
     * 描述
     */
    private String description;

    /**
     * 状态（0未上架，1已上架）
     */
    private Integer status;

    public static GoodsVo convert(Goods goods) {
        GoodsVo goodsVo = new GoodsVo();
        goodsVo.setId(goods.getId());
        goodsVo.setUpdateTime(DateUtil.format(goods.getUpdateTime()));
        goodsVo.setCreateTime(DateUtil.format(goods.getCreateTime()));
        goodsVo.setCategoryId(goods.getCategoryId());
        goodsVo.setCategoryName(goods.getCategoryName());
        goodsVo.setName(goods.getName());
        goodsVo.setPrice(goods.getPrice().toString());
        goodsVo.setUrl(goods.getUrl());
        goodsVo.setPublisher(goods.getPublisher());
        goodsVo.setPublisherName(goods.getPublisherName());
        goodsVo.setStock(goods.getStock());
        goodsVo.setDescription(goods.getDescription());
        goodsVo.setStatus(goods.getStatus());
        return goodsVo;
    }
}
